<?php

function dtxx($data_list,$dtxx_msg='',$dtxx_url='',$css=''){
	global $currentdate;
$return=print<<<GH
<table width="100%"  border="0" cellpadding="0">
<tr class="redb">
    <td width="338" height="40" valign="middle" align="right" class="$css">
	<!-- $dtxx_msg -->
	<a href="$dtxx_url"  target="_blank" class='blue'>更多</a></td>
  </tr>
  <tr class="fawenbg">
    <td height="200" valign="top">
<table width="100%"  border="0" cellpadding="0" cellspacing="3" class="indexlmtext">
            <tr align="left" height="2">
        <td width="283"></td>
        <td width="36"></td>
      </tr>
GH;

	foreach($data_list as $zywd){
	$msg=$title='';
$return.=print<<<GH
      <tr align="left">
        <td><img src='images/ind_13.jpg' border='0' />
GH;

			if(strlen($zywd['title'])>25){
				$title=cutstr($zywd['title'],24);
			}else{
				$title=$zywd['title'];
			}
		$msg="<a href='".$dtxx_url."&id=".$zywd['id']."'  target='_blank' title='标题：".$zywd['title']." &#13;&#10;录入：".$zywd['author']."&#13;&#10;日期：".$zywd['tdate']."' class='dong'>".$title."</a>";
		if($currentdate>=$zywd['tdate'])
		$msg.="<img src='/images/new.gif' width='23' height='16' border='0' />";
$datas=date('m-d',strtotime($zywd['tdate']));

$return.=print<<<GH
$msg</td>
        <td widzh="14%">$datas</td>
</tr>
GH;
		 }
$return.=print<<<GH
    </table> 
  </tr>
</table>
GH;
}



/*
*读取指定新闻信息
*根据指定ID值
*/
function news($id=0){//
    global $db;
	$news=array();
	$id=intval($id);
	if(!$id) return $news;
	$sql="select * from bl_dzgg where id='$id'";
	$news=$db->fetch_first($sql);
	return $news;
} // end func

/*
*读取指定类别新闻列表
*根据指定type值
*/
function newlist($sql){//
    global $db;
	$news=array();
//	echo "\nsql".$sql;
	$news=$db->fetch_all($sql);
	return $news;
} // end func

/*读取介绍信息*/
function abouts($id){//
    global $db;
	$id=intval($id)==0?1:intval($id);
	$news=array();
	$where='';
	$sql="select title,buid from bl_bzjj ";
	$news['all']=$db->fetch_all($sql);
	$sql="select title,content,buid from bl_bzjj where buid=$id";
//	echo "\nsql".$sql;
	$news['list']=$db->fetch_first($sql);
	if(empty($news['list'])){
		return array();
	}else{
		return $news;
	}
} // end func

/*读取生产日况信息*/
function products($id){//
    global $db;
	$id=intval($id)==0?1:intval($id);
	$news=array();
	$where='';
	$sql="select title,buid from bl_bzjj ";
	$news['all']=$db->fetch_all($sql);
	$sql="select title,content,buid from bl_bzjj where buid=$id";
//	echo "\nsql".$sql;
	$news['list']=$db->fetch_first($sql);
	if(empty($news['list'])){
		return array();
	}else{
		return $news;
	}
} // end func


/*读取指定栏目的子栏目的信息*/
function submenu($id){//
    global $db;
	$news=array();
	$id=intval($id);
	if(!$id){
		return $news;
	}
	$where='';
	$sql="select id,buname as name from bl_bume  where parentid=$id";
	$sql_self="select id,buname as name from bl_bume  where id=$id";
	//echo "\nsql".$sql;
	$news['list']=$db->fetch_all($sql);
	$news['self'][]=$db->fetch_first($sql_self);
	return $news;
} // end func


//提取月报表
function months_show(){//
    global $db;
	$sql="select m.tdate,m.yssr,(m.yssr-l.yssr_last)/m.yssr as yssr_last,m.fsx,(m.fsx-l.fsx_last)/m.fsx as fsx_last,fsd,ddx,wdblk from bl_months m join bl_months_last l on m.tdate=l.tdate;";
	$sql_last="select * from bl_months_last";
	//echo "\nsql".$sql;
	$news['list']=$db->fetch_all($sql);
	$sql="select sum(yssr) as yssr,sum(fsx) as fsx,fsd,ddx,wdblk from bl_months group by date_format(tdate,'%Y');";
	$news['total']=$db->fetch_first($sql);
	//print_r($news);die();
	return $news;
} // end func

//提取日报表
function days_show($day=''){//
    global $db;
	$news['total']=$news['list']='';
	if(empty($day)){
		$sql="select date_format(tdate,'%Y-%m') as tdate from bl_months";
		$news['total']=$db->fetch_all($sql);
	}else{
		$sql="select * from bl_scrk where date_format(tdate,'%Y%m') ='$day' order by tdate";
		$news['list']['list']=$db->fetch_all($sql);
		$sql="select sum(yssr) as yssr,sum(fsjzx) as fsjzx,sum(fsd) as fsd,sum(ddjzx) as ddjzx,sum(wdblk) as wdblk from bl_scrk where date_format(tdate,'%Y%m') ='$day' group by date_format(tdate,'%Y%m');";
		$news['list']['total']=$db->fetch_first($sql);
	}
	//print_r($news);die();
	return $news;
} // end func

//bl_task
//提取日报表
function graph_show($id=''){//
    global $db;
	$news['total']=$news['list']='';
	if(empty($day)){
		$sql="select date_format(tdate,'%Y-%m') as tdate from bl_months";
		$news['total']=$db->fetch_all($sql);
	}else{
		$sql="select * from bl_scrk where date_format(tdate,'%Y%m') ='$day' order by tdate";
		$news['list']['list']=$db->fetch_all($sql);
		$sql="select sum(yssr) as yssr,sum(fsjzx) as fsjzx,sum(fsd) as fsd,sum(ddjzx) as ddjzx,sum(wdblk) as wdblk from bl_scrk where date_format(tdate,'%Y%m') ='$day' group by date_format(tdate,'%Y%m');";
		$news['list']['total']=$db->fetch_first($sql);
	}
	//print_r($news);die();
	return $news;
} // end func


/*读取指定栏目的导航栏的信息*/
function leftmenu($type){//
    global $db;
	$news=array();
	$type=trim($type);
	if(!$type){
		return $news;
	}
	$sql="select id,buname from bl_bume  where types='$type'";
	$query = $db-> query($sql);
	while ($resulte = $db-> fetch_array($query)) {
		$news[$resulte['id']]=$resulte['buname'];
	} 
	return $news;
} // end func


function dateDiff($interval,$dateTimeBegin,$dateTimeEnd) {
         //Parse about any English textual datetime
         //$dateTimeBegin, $dateTimeEnd

         $dateTimeBegin=strtotime($dateTimeBegin);
         if($dateTimeBegin === -1) {
           return("..begin date Invalid");
         }

         $dateTimeEnd=strtotime($dateTimeEnd);
         if($dateTimeEnd === -1) {
           return("..end date Invalid");
         }

         $dif=$dateTimeEnd - $dateTimeBegin;

         switch($interval) {
           case "s"://seconds
               return($dif);

           case "n"://minutes
               return(floor($dif/60)); //60s=1m

           case "h"://hours
               return(floor($dif/3600)); //3600s=1h

           case "d"://days
               return(floor($dif/86400)); //86400s=1d

           case "ww"://Week
               return(floor($dif/604800)); //604800s=1week=1semana

           case "m": //similar result "m" dateDiff Microsoft
               $monthBegin=(date("Y",$dateTimeBegin)*12)+
                 date("n",$dateTimeBegin);
               $monthEnd=(date("Y",$dateTimeEnd)*12)+
                 date("n",$dateTimeEnd);
               $monthDiff=$monthEnd-$monthBegin;
               return($monthDiff);

           case "yyyy": //similar result "yyyy" dateDiff Microsoft
               return(date("Y",$dateTimeEnd) - date("Y",$dateTimeBegin));

           default:
               return(floor($dif/86400)); //86400s=1d
         }

       } 
?>